package javaCode.chapter07.Homework;

public class Homework01 {
    public static void main(String[] args) {

        Person[] p1 = new Person[3];
        p1[0] = new Person("jack", 35, "搬砖");
        p1[1] = new Person("smith", 22, "会计");
        p1[2] = new Person("nick", 25, "码农");

        for (int i = 0; i < p1.length; i++) {
            for (int j = 0; j < p1.length - 1 - i; j++) {
                //按照age 从大到小进行排序
                if (p1[j].getAge() < p1[j + 1].getAge()) {
                    Person temp = p1[j];
                    p1[j] = p1[j + 1];
                    p1[j + 1] = temp;
                }
            }
        }

        for (int i = 0; i < p1.length; i++) {
            System.out.println(p1[i] + " ");
        }
    }
}

//定义一个Person类 {name,age,job}，初始化Person 对象数组，有3个person对象，并按照age 从大到小进行排序，提示冒泡排序
class Person {
    private String name;
    private int age;
    private String job;

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }
}